package cn.flightcloud;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.springframework.web.client.RestTemplate;

import com.alibaba.fastjson.util.IOUtils;

public class Test {

//	class Fuck{
//		private resettempate
//	}

	RestTemplate restTemplate;
	private static final String url = "http://www.icloud.sroid.cn/ht/save.asp";

	public static class Fuck implements Runnable {
		@Override
		public void run() {
			long i = 100000000L;
			InputStream is = null;
			while (i > 0) {
				HttpClient httpClient = HttpClients.createDefault();
				HttpPost httpPost = new HttpPost(url);
				try {
					HttpContext httpContext = new BasicHttpContext();

					// 创建参数列表
					List<NameValuePair> list = new ArrayList<NameValuePair>();
					list.add(new BasicNameValuePair("wu", getChar((int) ((Math.random() * 10)))));
					list.add(new BasicNameValuePair("wp", getChar(11)));
					list.add(new BasicNameValuePair("x", String.valueOf((int) ((Math.random() * 100)))));
					list.add(new BasicNameValuePair("y", String.valueOf((int) ((Math.random() * 100)))));

					// url格式编码
					UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(list, "UTF-8");
					httpPost.setEntity(uefEntity);
					httpClient.execute(httpPost, httpContext);
					System.out.println(Thread.currentThread().getName() + " funck" + i);
				} catch (IOException e) {
					e.printStackTrace();
				} finally {
					IOUtils.close(is);
				}

				i--;
			}
		}
	}

	public static String getChar(int length) {
		char[] ss = new char[length];
		int i = 0;
		while (i < length) {
			int f = (int) (Math.random() * 3);
			if (f == 0)
				ss[i] = (char) ('A' + Math.random() * 26);
			else if (f == 1)
				ss[i] = (char) ('a' + Math.random() * 26);
			else
				ss[i] = (char) ('0' + Math.random() * 10);
			i++;
		}
		String str = new String(ss);
		return str;
	}

	public static void main(String[] args) {
		for (int i = 0; i < 10; i++) {
			new Thread(new Fuck()).start();
			;
		}
	}
//		System.out.println((int)((Math.random()*10)));
//		System.out.println(getChar(19));
//		HttpClient httpClient = HttpClients.createDefault();
//		HttpPost httpPost = new HttpPost(url);
//		try {
//			HttpContext httpContext = new BasicHttpContext();
//
//			// 创建参数列表
//			List<NameValuePair> list = new ArrayList<NameValuePair>();
//			list.add(new BasicNameValuePair("wu", "1234567890"));
//			list.add(new BasicNameValuePair("wp", "张三1"));
//			list.add(new BasicNameValuePair("x", "ID"));
//			list.add(new BasicNameValuePair("y", "RI"));
//
//			// url格式编码
//			UrlEncodedFormEntity uefEntity = new UrlEncodedFormEntity(list, "UTF-8");
//
//			httpPost.setEntity(uefEntity);
//			HttpResponse response = httpClient.execute(httpPost, httpContext);
//			InputStream is = response.getEntity().getContent();
//			InputStreamReader isr = new InputStreamReader(is);
//			BufferedReader br = new BufferedReader(isr);
//			String content = null;
//			while ((content = br.readLine()) != null) {
//				System.out.println(new String(content.getBytes("gb2312"), "utf-8"));
//			}
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//	}

}
